package com.pb.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pb.exception.BusinessException;
import com.pb.mapper.SubjectMapper;
import com.pb.pojo.Clazz;
import com.pb.pojo.PageResult;
import com.pb.pojo.Subject;
import com.pb.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubjectServiceImpl implements SubjectService {

    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public void save(Subject subject) {
        subjectMapper.insert(subject);
    }

    @Override
    public PageResult page(String name, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<Subject> dataList = subjectMapper.list(name);
        Page<Subject> p = (Page<Subject>) dataList;

        return new PageResult(p.getTotal(), p.getResult());
    }

    @Override
    public Subject getInfo(Integer id) {
        return subjectMapper.getInfo(id);
    }

    @Override
    public void update(Subject subject) {
        subjectMapper.update(subject);
    }

    @Override
    public void deleteById(Integer id) {
        subjectMapper.deleteById(id);
    }

    @Override
    public List<Subject> findAll() {
        return subjectMapper.findAll();
    }
}
